package cn.vendsystem.com.mapper;

import cn.vendcommon.com.entity.Machine;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MachineMapper {

    /** 新增售卖机 */
    @Insert("INSERT INTO machine (longitude, latitude, status) " +
            "VALUES (#{longitude}, #{latitude}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "machineId")
    int insert(Machine machine);

    /** 根据ID删除售卖机 */
    @Delete("DELETE FROM machine WHERE machine_id = #{id}")
    int deleteById(int id);

    /** 更新售卖机信息 */
    @Update("UPDATE machine SET longitude=#{longitude}, latitude=#{latitude}, status=#{status} " +
            "WHERE machine_id=#{machineId}")
    int update(Machine machine);

    /** 根据ID查询售卖机 */
    @Select("SELECT machine_id AS machineId, longitude, latitude, status " +
            "FROM machine WHERE machine_id = #{id}")
    Machine selectById(int id);

    /** 查询所有售卖机 */
    @Select("SELECT machine_id AS machineId, longitude, latitude, status FROM machine")
    List<Machine> selectAll();
}
